import React, { Component } from 'react';
import { connect } from 'react-redux'
class Index extends Component {
  render() {
    const { location, history, addCar } = this.props
    const { state: { title, desc, url } } = location
    return (
      <div>
      <button onClick={ () => history.goBack() }>返回上一页</button>
       <img src={ url } alt="" width="100%"/>
       <h3>{title}</h3>
       <p>{desc}</p>
       <button onClick={ () => addCar(location.state) }>加入购物车</button>
      </div>
    );
  }
}

const mapStateToProps = state => {
  return {

  }
}

const mapDispatchToProps = dispatch => {
  return {
    addCar(payload) {
      dispatch({ type: 'ADD_CAR',  payload})
    }
  }
}

export default connect(mapStateToProps ,mapDispatchToProps)(Index);
